<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            padding: 0;
            margin: 0;
        }
        body{
            width: 100%;
            background: url(./img/login-background.jpg);
            background-size: cover;
        }
        main{
            margin: 100px auto;
            text-align: center;
            width: 400px ;
            height: 400px;
            border-radius: 10px;
            background-color:aliceblue ;
        }
        main h2{
            height: 100px;
            line-height: 100px;
        }
        main footer{
            height: 200px;
        }
        main footer input, main footer button{
            box-sizing: border-box;
            border-radius: 5px;
            width: 80%;
            height: 40px;
            line-height: 40px;
            margin-bottom: 20px;
            outline: none;
            border: 1px solid rgb(197, 197, 197);
        }
        main footer input{
            padding-left: 20px;
        }
        main footer button{     
            color: white;
            color: 20px;
            background-color: rgb(43, 140, 251);
        }
        main footer .zhanghao{
            width: 50%;
            float: right;
        }
        main footer .zhanghao a{
            text-decoration: none;
        }
    </style>
</head>
<body>
    <main>
        <h2>后台登录系统</h2>
        <footer>
            <input type="text" placeholder="账号">
            <input type="password" placeholder="密码">
            <input type="password" placeholder="确认密码">
            <button>注册</button>
            <div class="zhanghao"><a href="./login.html">使用已有账号登录</a></div>
        </footer>
    </main>
</body>
</html>
<script src="./axios.min.js"></script>
<script>
    // 注册

    //获取输入框和按钮
    let inputs =document.querySelectorAll('input')
    var registerBtn = document.querySelector('button')
    registerBtn.onclick = function(){
        if(
            inputs[0].value &&
            inputs[1].value &&
            inputs[2].value 
        ){
            if(/^1[3-9]\d{9}$/.test(inputs[0].value)&&inputs[1].value ==inputs[2].value){
                axios.post('/user/register',{
                    phone:inputs[0].value,
                    pass:inputs[1].value,
                }).then((res)=>{
                    // console.log(res.data);
                    alert('恭喜您，注册成功')
                })
            }else if(/^1[3-9]\d{9}$/.test(inputs[0].value) == false){
                alert('手机号格式不正确！')
            }else{
                alert('两次密码不一致！')
            }
        }else{
            alert('注册信息不完整！')
        }
    }
</script>